import 'dotenv/config';
import { TextEncoder } from 'node:util';
import * as jose from 'jose';

const secret = new TextEncoder().encode(process.env.JWT_SECRET);
const alg = 'HS256';

const jwt = await new jose.SignJWT({ username: 'peter', role: ['admin'] })
  .setProtectedHeader({ alg })
  .setIssuedAt()
  .setIssuer('some issuer')
  .setAudience('some audience')
  .setExpirationTime('2h')
  .sign(secret);

const verify = await jose.jwtVerify(jwt, secret, {
  issuer: 'some issuer',
  audience: 'some audience',
});

console.log(verify);

// const { publicKey, privateKey } = await jose.generateKeyPair('PS256');
// console.log(publicKey);
// console.log(privateKey);

// const secret2 = await jose.generateSecret('HS256');
// console.log(secret2);
